﻿// --- Copyright (c) 2010 Steven Hartgers ---
// Copyright (C) 2010 Steven Hartgers All rights are reserved.
// Author contact: fiinix00/at\gmail.com
// ------------------------------------------------------------------------
// This program is free software: you can redistribute it and/or modify 
// it under the terms of the GNU General Public License as published by 
// the Free Software Foundation, either version 3 of the License, or 
// (at your option) any later version. 
//  
// This program is distributed in the hope that it will be useful, 
// but WITHOUT ANY WARRANTY; without even the implied warranty of 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
// GNU General Public License for more detail
//  
// You should have received a copy of the GNU General Public License 
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// ------------------------------------------------------------------------
// COPYRIGHT NOTICE: This copyright notice may NOT be removed, obscured or modified 
// without written consent from the author.
// --- End copyright notice --- 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using Hack.SystemAPI;
namespace Hack.SystemAPI
{
    public static class Icons
    {
        public static Icon GetShellIcon(IconTypes index)
        {
            IntPtr Hicon = NativeDlls.ExtractIcon(
               IntPtr.Zero, @"C:\WINDOWS\System32\shell32.dll", (int)index);
            Icon icon = Icon.FromHandle(Hicon);
            return icon;
        }
        public static Icon GetFileIcon(string fileName, SHGFISize flags)
        {
            var shinfo = new SHFILEINFO();
            var hImgSmall = NativeDlls.SHGetFileInfo(fileName, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), (uint)SHGFISize.SHGFI_ICON | (uint)flags | (uint)0x000000010);
            var icon = (Icon)Icon.FromHandle(shinfo.hIcon).Clone();
            NativeDlls.DestroyIcon(shinfo.hIcon);
            return icon;
        }


        public enum SHGFISize : uint
        {
            SHGFI_ICON = 0x100,
            SHGFI_LARGEICON = 0x0,
            SHGFI_SMALLICON = 0x1
        }
        public enum IconTypes : int
        {
            Unknown_Document = 0,
            Default_document = 1,
            Default_application = 2,
            Closed_folder = 3,
            Open_folder = 4,
            _5_14inch_disk = 5,
            _3_12inch_disk = 6,
            Removable_drive = 7,
            Hard_disk_drive = 8,
            Network_drive = 9,
            Network_drive_offline = 10,
            CDROM_drive = 11,
            RAM_chip = 12,
            Entire_network = 13,
            Network_Service = 14,
            My_Computer = 15,
            Printer_1 = 16,
            Network_Neighborhood = 17,
            Network_Workgroup = 18,
            Start_Menu_Programs = 19,
            Start_Menu_Documents = 20,
            Start_Menu_Settings = 21,
            Start_Menu_Find = 22,
            Start_Menu_Help = 23,
            Start_Menu_Run = 24,
            Start_Menu_Susspend = 25,
            Start_Menu_Docking = 26,
            Start_Menu_Shutdown = 27,
            Sharing_overlay___hand = 28,
            Shortcut_overlay___small_arrow = 29,
            Default_printer_overlay___small_tick = 30,
            Recycle_bin___empty = 31,
            Recycle_bin___full = 32,
            DialUp_Network_Folder = 33,
            Desktop = 34,
            Control_Panel = 35,
            Start_Menu_Program_Group = 36,
            Printers_Folder = 37,
            Fonts_Folder = 38,
            Taskbar_Windows_flag = 39,
            Audio_CD___music = 40,
            Novel_Green_tree = 41,
            Multiple_documents = 42,
            Favorites = 43,
            Start_Menu_Logoff = 44,
            Monitor_on_Computer_case = 45,
            Control_Panel_folder = 46,
            Lock = 47,
            Hibernate = 48,
            Network_printer_1 = 49,
            Print_to_file___3_12In_disk = 50,
            Alternate_full_Recycle_Bin_1 = 51,
            Alternate_full_Recycle_Bin_2 = 52,
            Alternate_full_Recycle_Bin_3 = 53,
            Document_to_document = 54,
            Documents_folder_to_folder = 55,
            Pen_writing_a_folder_label = 56,
            Comp, _gears, _open_folder = 57,
            Configuration_file = 58,
            Text_file = 59,
            Window_with_gears = 60,
            Gears_image_on_paper = 61,
            Font_file = 62,
            TrueType_font_file = 63,
            Window_hourglass_cursor = 64,
            Are_you_suredelete_files = 65,
            Tape_backup = 66,
            CD_in_drive = 67,
            Defrag = 68,
            Printer_2 = 69,
            Network_printer_2 = 70,
            Print_to_file = 71
        }
    }
    [StructLayout(LayoutKind.Sequential)]
    public struct SHFILEINFO
    {
        public IntPtr hIcon;
        public IntPtr iIcon;
        public uint dwAttributes;

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szDisplayName;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
        public string szTypeName;
    }
}
/*
 CODE USED WHEN GENERATING IF SOMEONE NEED

string items = @"0;;;;Unknown Document
1;;;;Default document
2;;;;Default application
3;;;;Closed folder
4;;;;Open folder
5;;;;5 1/4-inch disk
6;;;;3 1/2-inch disk
7;;;;Removable drive
8;;;;Hard disk drive
9;;;;Network drive
10;;;;Network drive offline
11;;;;CD-ROM drive
12;;;;RAM chip
13;;;;Entire network
14;;;;Network Service
15;;;;My Computer
16;;;;Printer
17;;;;Network Neighborhood
18;;;;Network Workgroup
19;;;;Start Menu Programs
20;;;;Start Menu Documents
21;;;;Start Menu Settings
22;;;;Start Menu Find
23;;;;Start Menu Help
24;;;;Start Menu Run
25;;;;Start Menu Susspend
26;;;;Start Menu Docking
27;;;;Start Menu Shutdown
28;;;;Sharing overlay (hand)
29;;;;Shortcut overlay (small arrow)
30;;;;Default printer overlay (small tick)
31;;;;Recycle bin (empty)
32;;;;Recycle bin (full)
33;;;;Dial-up Network Folder
34;;;;Desktop
35;;;;Control Panel
36;;;;Start Menu Program Group
37;;;;Printers Folder
38;;;;Fonts Folder
39;;;;Taskbar Windows flag
40;;;;Audio CD (music)
41;;;;Novel Green tree
42;;;;Multiple documents
43;;;;Favorites
44;;;;Start Menu Logoff
45;;;;Monitor on Computer case (?)
46;;;;Control Panel folder (?)
47;;;;Lock
48;;;;Hibernate
49;;;;Network printer
50;;;;Print to file (3 1/2-in disk)
51;;;;Alternate full Recycle Bin
52;;;;Alternate full Recycle Bin
53;;;;Alternate full Recycle Bin
54;;;;Document to document
55;;;;Documents folder to folder
56;;;;Pen writing a folder label
57;;;;Comp, gears, open folder
58;;;;Configuration file
59;;;;Text file
60;;;;Window with gears
61;;;;Gears image on paper
62;;;;Font file
63;;;;TrueType font file
64;;;;Window - hourglass cursor
65;;;;Are you suredelete files?
66;;;;Tape backup
67;;;;CD in drive
68;;;;Defrag
69;;;;Printer
70;;;;Network printer
71;;;;Print to file";
            string[] item = items.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            string[] newitems = new string[72];
            int i = 0;
            foreach (string str in item)
            {
                
                string[] innerItem = str.Split(new string[] { ";;;;" }, StringSplitOptions.None);
                //
                ////...\r\n...
                //string[] innerItem = str.Split(new string[] { "...\r\n..." }, StringSplitOptions.None);
                newitems[i++] = innerItem[1].Replace(' ', '_').Replace("(","__") + " = " + (Convert.ToInt32((innerItem[0]))) + ",";
                
            }
            newitems.ForEach((s) => { s.Out(); });
 */